package com.hzdesk.media.koreabatchmatvector.fragment.fragment_view;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.config.AppConfig;
import com.hzdesk.media.koreabatchmatvector.config.RxBusUtil;
import com.hzdesk.media.koreabatchmatvector.fragment.fragment_contract.SetContract;
import com.hzdesk.media.koreabatchmatvector.fragment.fragment_persenter.SetPersenter;
import com.hzdesk.media.koreabatchmatvector.utils.RxBus;
import com.orhanobut.logger.Logger;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2018/6/22.
 * 杭州席媒科技有限公司  Developers  刘传华  15
 * 佛祖镇楼 bug辟易
 */

public class SetFragment extends BaseFragment implements SetContract.ISetView{
    @BindView(R.id.fragment_my_set_iv_back)
    ImageView fragmentMySetIvBack;
    @BindView(R.id.fragment_my_set_et_name)
    EditText fragmentMySetEtName;
    @BindView(R.id.fragment_my_set_tv_mouse_set)
    TextView fragmentMySetTvMouseSet;
    @BindView(R.id.fragment_my_set_ll_mouse_set)
    LinearLayout fragmentMySetLlMouseSet;
    @BindView(R.id.fragment_my_set_ll_config_file)
    LinearLayout fragmentMySetLlConfigFile;
    @BindView(R.id.fragment_my_set_ll_logo_image)
    LinearLayout fragmentMySetLlLogoImage;
    @BindView(R.id.fragment_my_set_ll_block_length)
    LinearLayout fragmentMySetLlBlockLength;
    @BindView(R.id.fragment_my_set_tv_screen_path)
    TextView fragmentMySetTvScreenPath;
    @BindView(R.id.fragment_my_set_tv_video_path)
    TextView fragmentMySetTvVideoPath;
    @BindView(R.id.fragment_my_set_ll_video_path)
    LinearLayout fragmentMySetLlVideoPath;
    @BindView(R.id.fragment_my_set_tv_binding_cloud_service)
    TextView fragmentMySetTvBindingCloudService;
    @BindView(R.id.fragment_my_set_ll_binding_cloud_service)
    LinearLayout fragmentMySetLlBindingCloudService;
    @BindView(R.id.fragment_my_set_tv_about_device)
    TextView fragmentMySetTvAboutDevice;
    @BindView(R.id.fragment_my_set_ll_about_device)
    LinearLayout fragmentMySetLlAboutDevice;
    Unbinder unbinder;
    @BindView(R.id.fragment_my_set_ll_screen_path)
    LinearLayout fragmentMySetLlScreenPath;

    private SetPersenter mSetPersenter = new SetPersenter(this);

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_my_set, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mSetPersenter.initDate(fragmentMySetEtName,mcontext);
    }
    @OnClick({R.id.fragment_my_set_iv_back, R.id.fragment_my_set_ll_mouse_set,
            R.id.fragment_my_set_ll_config_file, R.id.fragment_my_set_ll_logo_image,
            R.id.fragment_my_set_ll_block_length, R.id.fragment_my_set_ll_video_path,
            R.id.fragment_my_set_ll_binding_cloud_service, R.id.fragment_my_set_ll_about_device,
            R.id.fragment_my_set_ll_screen_path})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.fragment_my_set_iv_back:                                                      // 返回
                mSetPersenter.SonClickedendMessage(RxBusUtil.SET_FRAGMENT_BACK);                    // 设置页面的返回 10001
                break;
            case R.id.fragment_my_set_ll_mouse_set:                                                 //批注功能
                mSetPersenter.SonClickedendMessage(RxBusUtil.CHANGE_MOUSE_LIST_FRAGMENR);           // 显示鼠标列表页面 1
                break;
            case R.id.fragment_my_set_ll_config_file:                                               //管理配置文件
                mSetPersenter.ConfigFileManger(mcontext);
                break;
            case R.id.fragment_my_set_ll_logo_image:                                                //设置LOGO图片
                break;
            case R.id.fragment_my_set_ll_block_length:                                              //分段时长
                break;
            case R.id.fragment_my_set_ll_video_path:                                                //视频文件路径
                mSetPersenter.SonClickedendMessage(RxBusUtil.CHANGE_SELECT_FILE_FRAGMENT);          // 显示选择文件页面 3
                break;
            case R.id.fragment_my_set_ll_binding_cloud_service:                                     //绑定云服务
                mSetPersenter.SonClickedendMessage(RxBusUtil.CHANGE_BOUND_CLOUD_SERVICE_FRAGMENT);  //  显示绑定云服务页面 5
                break;
            case R.id.fragment_my_set_ll_about_device:                                              //关于可立批
                mSetPersenter.SonClickedendMessage(RxBusUtil.CHANGE_ABOUT_FRAGMENT);                // 显示关于可立批页面 6
                break;
            case R.id.fragment_my_set_ll_screen_path:                                               //截图文件路径
                mSetPersenter.SonClickedendMessage(RxBusUtil.CHANGE_SELECT_FILE_FRAGMENT);          // 显示选择文件页面 3
                break;
        }
    }
    @Override
    public void initDate() {
        SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mcontext);
        String video_save_path = mSharedPreferences.getString(AppConfig.Video_SAVE_PATH, "");
        String screen_save_path  =  mSharedPreferences.getString(AppConfig.SCREEN_SAVE_PATH, "");

        fragmentMySetEtName.setText("视频批注会议01");
        fragmentMySetTvScreenPath.setText(screen_save_path);
        fragmentMySetTvVideoPath.setText(video_save_path);
    }

    @Override
    public void meetName(String msg) {
        fragmentMySetEtName.setText(msg);
    }

    @Override
    public String getMeetName() {
        return fragmentMySetEtName.getText().toString().trim();
    }

    @Override
    public void sendMessage(int pager) {
        RxBus.getInstance().send(pager);
    }
    @Override
    public void focusChange(View v) {
        InputMethodManager imm = ( InputMethodManager ) v.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );
        if ( imm.isActive( ) ) {
            imm.hideSoftInputFromWindow( v.getApplicationWindowToken( ) , 0 );
        }
    }

    @Override
    public void onStop() {
        super.onStop();
        // 将会议名称存储到数据库
        mSetPersenter.SaveMeetName(mcontext);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        RxBus.getInstance().unSubcribe();
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


}
